package com.bbt.dormassistant.controller;

import com.bbt.dormassistant.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@Api(tags = "评论接口")
@RequestMapping("/comment")
@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;


    @ApiOperation(value = "添加评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "messageId", value = "文章ID", required = true, dataType = "int"),
            @ApiImplicitParam(name = "text", value = "评论内容", required = true, dataType = "String")
    })
    @PostMapping(value = "/addComment")
    public Map<String,Object> addComment(@RequestParam(value = "userId") String userId,
                                              @RequestParam(value = "messageId") Integer messageId,
                                              @RequestParam(value = "text") String text){
        Map<String,Object> map =  new HashMap<>();
        map.put("success",commentService.addComment(userId,messageId,text));
        return map;
    }


    @ApiOperation(value = "查询评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currIndex", value = "当前页码(可选项)", required = false, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页大小(可选项)", required = false, dataType = "int")
    })
    @GetMapping(value = "/queryAllComment")
    public Map<String,Object> queryAllComment(@RequestParam(value = "currIndex",required = false) Integer currIndex,
                                              @RequestParam(value = "pageSize",required = false) Integer pageSize){
        Map<String,Object> map =  new HashMap<>();
        map.put("comments",commentService.queryAll(currIndex,pageSize));
        return map;
    }


    @ApiOperation(value = "根据文章ID查询搞文章的所有评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageId", value = "文章ID", required = true, dataType = "int")
    })
    @GetMapping(value = "/queryAllByMessageId")
    public Map<String,Object> queryAllByMessageId(@RequestParam(value = "messageId") Integer messageId){
        Map<String,Object> map =  new HashMap<>();
        map.put("comments",commentService.queryAllByMessageId(messageId));
        return map;
    }




}
